<?php

namespace frame;
use Smarty\Smarty;

class BaseApi
{
    public function __construct()
    {
        $this->initialize();
    }
    // 视图 Smarty使用
    public function view($view = 'index', $data = [])
    {
        require ROOT_PATH . 'vendor/autoload.php';
        $smarty = new Smarty;
        $template =  ROOT_PATH . "app" . DS . APP . DS . 'view' . DS;
        $smarty->setTemplateDir($template);
        // 系统变量
        $sys = config('system');
        $smarty->assign($data);
        $smarty->assign(['sys' => $sys]);
        extract($data);
        $html = VIEW_PATH . $view . '.html';
        $ph = VIEW_PATH . $view . '.php';
        if (file_exists($html)) {
            $smarty->display($html);
        } else if (file_exists($ph)) {
            $smarty->display($ph);
        } else {
            include ROOT_PATH . 'app/common/view/404.html';
        }
    }
    public  function initialize()
    {
        // 引进公共函数
        include APP_PATH . 'common.php';
        // 助手函数
        include ROOT_PATH . 'frame' . DS . 'lib' . DS . 'Fun.php';
    }
 
}
